package org.dromara.web.plugins.udun;


import com.alibaba.fastjson.JSONObject;
import com.uduncloud.sdk.client.UdunClient;
import com.uduncloud.sdk.domain.Address;
import lombok.extern.slf4j.Slf4j;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UDUNWalletService implements InitializingBean {


    @Autowired
    OkHttpClient okHttpClient;

    private String COIN_TYPE_USDT_ERC20 = "60";
    private String COIN_TYPE_USDT_TRC20 = "195";
    public static final String UDUN_MERCHANT_ID = "317519";
    public static final String UDUN_API_KEY = "836bb54ef5bd00e47c4a2df49314832a";

    // 充值回调地址
    private String NOTIFY_URL = "https://callback.recharge.com/api/udun/notify";

    private String UDUN_BASE_DOMAIN = "https://sig11.udun.io";
    private String UDUN_CREATE_ADDRESS_API = UDUN_BASE_DOMAIN + "/mch/address/create";

    UdunClient udunClient;


    @Override
    public void afterPropertiesSet() throws Exception {
        udunClient = new UdunClient(UDUN_BASE_DOMAIN, UDUN_MERCHANT_ID, UDUN_API_KEY,NOTIFY_URL);
    }

    public String createAddress() {

        Address address = udunClient.createAddress(COIN_TYPE_USDT_ERC20);
        return address.getAddress();
    }

}
